package com.example.multitenant.controller

import com.example.multitenant.model.Person
import com.example.multitenant.model.Persons
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RestController

/**
 * @author xiang
 * @Date 2022/9/3 17:26
 **/

@RestController
class TestController {

    companion object {
        private const val TAG = "TestController"
    }

    @Autowired
    private lateinit var persons: Persons

    @Autowired
    private lateinit var service: TestService

    @PostMapping("/person")
    fun addPerson(name: String): String {
        persons.save(Person(name = name))
        return "success"
    }

    @GetMapping("/person")
    fun getPersons(): List<Person> {
        return persons.findAll()
    }

    @GetMapping("/async")
    fun testAsync(): String {
        persons.findAll()
        service.testAsync()
        return "success"
    }

}